#ifndef _SOTA_ONENET_H_
#define _SOTA_ONENET_H_
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>

#include "encryption.h"

enum SotaProcess
{
    SOTA_GET_DEVICE_ID  = 0, 
    SOTA_REPORT_VERSION,
    SOTA_CHECK_TASK,
    SOTA_CHECK_TOKEN,
    SOTA_DOWNLOAD,
    SOTA_REPORT_STATUS
};

struct SotaOnenet
{
    int     socket; 
    char    _onenetId[16];
    char    _token[28];
    char    _md5String[36];
    uint8_t  _md5[16];
    char    _target[16];
	char	_targetResume[16];
    int     _sizePackage;
    int     _sizeDownloaded;
    char    *pid;
    char    *deviceId;
    char    *version;
    char    *auth;
	int 	resumeIndex;
    
    struct MD5 md5Obj;
    uint8_t md5Final[16];
    
    enum SotaProcess process;
};
/* typedef -------------------------------------------------------------------*/
/* define --------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
/* function prototypes -------------------------------------------------------*/
void SotaOnenet_Init(struct SotaOnenet *sotaOnenet, int socket, char *pid, char *deviceId, char *version, char *auth);
void SotaOnenet_Process(void *ptr);

void SotaOnenet_ResumeBreak(struct SotaOnenet *sotaOnenet, char *target, int startIndex);
void SotaOnenet_SaveBreak(struct SotaOnenet *sotaOnenet, char *target, int *startIndex);
void SotaOnenet_ClearBreak(char *target, int *startIndex);

/* functions -----------------------------------------------------------------*/
#endif
